package com.springboot.mybatis.controller;

import com.springboot.mybatis.entity.User;
import com.springboot.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @version V1.0
 * @program: mybatis
 * @description
 * @author: 张要廷<zhang_yt @ suixingpay.com>
 * @create: 2019/10/21 18:57
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 新增用户信息，全属性
     * @param user
     * @return
     */
    @PostMapping("/save/userAllParam")
    public int saveUserAllParam(@RequestBody User user){
        return userService.saveUserAllParam(user);
    }

    /**
     * 新增用户信息,按照条件增加信息
     * @param user
     * @return
     */
    @PostMapping("/save/userSelective")
    public int saveUserSelective(@RequestBody User user){
        return userService.saveUserSelective(user);
    }

    /**
     * 模糊查询用户信息
     * @param userName
     * @return
     */
    @GetMapping("/like/name")
    public List<User> findUserLikeName(@RequestParam("userName") String userName){
        List<User> userLikeName = userService.findByUserName(userName);
        return userLikeName;
    }

    /**
     * 模糊查询用户信息
     * @param userName
     * @return
     */
    @GetMapping("/like/name2")
    public List<User> findUserLikeName2(@RequestParam("userName") String userName){
        List<User> userLikeName = userService.findByUserName2(userName);
        return userLikeName;
    }

    /**
     * 通过用户对象查询用户信息
     * @param user
     * @return
     */
    @PostMapping("/find/one")
    public User findOne(@RequestBody User user){
        User one = userService.findOne(user);
        return one;
    }

    /**
     * 通过用户对象查询用户信息
     * @param user
     * @return
     */
    @PostMapping("/find/one1")
    public User findOne1(@RequestBody User user){
        User one = userService.findOne1(user);
        return one;
    }

    /**
     * 通过用户对象查询用户信息
     * @param user
     * @return
     */
    @PostMapping("/find/one2")
    public User findOne2(@RequestBody User user){
        User one = userService.findOne2(user);
        return one;
    }


    /**
     * 通过用户名列表查询用户信息
     * @param userNameList
     * @return
     */
    @PostMapping("/find/usersByNameList")
    public List<User> findUsersByNames(@RequestBody List<String> userNameList){
        List<User> users = userService.findUsersByNames(userNameList);
        return users;
    }


    /**
     * 通过id查询用户
     * @param id
     * @return
     */
    @GetMapping("/find/annotation/userById")
    public User findUserById(@RequestParam("id") String id){
        return userService.findUserById(id);
    }

    /**
     * 通过id查询用户
     * @param id
     * @return
     */
    @GetMapping("/find/annotation/userById2")
    public User findUserById2(@RequestParam("id") String id){
        return userService.findUserById2(id);
    }

    /**
     * 查询用户订单信息
     * @param id
     * @return
     */
    @GetMapping("/find/userOrders")
    public User findUserOrdersById(@RequestParam("id") String id){
        return userService.findUserOrdersById(id);
    }

    /**
     * 查询用户订单信息
     * @param id
     * @return
     */
    @GetMapping("/find/userOrders2/{id}")
    public User findUserOrdersById2(@PathVariable(value = "id") String id){
        return userService.findUserOrdersById2(id);
    }

    /**
     * 删除用户信息
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public int delUserById(@PathVariable(value = "id")  String id){
        return userService.delUserById(id);
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @PostMapping("/update/user")
    public int updateUserByPrimaryKeySelective(@RequestBody User user){
        return userService.updateUserByPrimaryKeySelective(user);
    }


    /**
     * 通过id查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/find/provider")
    public User findUserByIdProvider(@RequestParam("id")String id){
        return userService.findUserByIdProvider(id);
    }

}
